﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_AdminRole_Manage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            PopulateAdminRole();

    }

    public void PopulateAdminRole()
    {
        lvAdminRole.DataSource = AdminRole.GetAllByConditon(txtKey.Text);
        lvAdminRole.DataBind();
    }

    protected void lvAdminRole_ItemCanceling(object sender, ListViewCancelEventArgs e)
    {
        lvAdminRole.EditIndex = -1;
        PopulateAdminRole();
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        PopulateAdminRole();
    }

    protected void lvAdminRole_ItemDeleting(object sender, ListViewDeleteEventArgs e)
    {
        int ID = DongDong.Common.Misc.ConvertToInt(lvAdminRole.DataKeys[e.ItemIndex].Value);
        AdminRole.Delete(ID);
        PopulateAdminRole();
    }
    protected void lvAdminRole_ItemEditing(object sender, ListViewEditEventArgs e)
    {
        lvAdminRole.EditIndex = e.NewEditIndex;
        PopulateAdminRole();
    }
    protected void lvAdminRole_ItemUpdating(object sender, ListViewUpdateEventArgs e)
    {
        int ID = DongDong.Common.Misc.ConvertToInt(lvAdminRole.DataKeys[e.ItemIndex].Value);
        AdminRole objAdminRole = AdminRole.Get(ID);
        var item = lvAdminRole.Items[e.ItemIndex];
        TextBox txtEdiName = (TextBox)item.FindControl("txtEdiName");
        objAdminRole.RoleName = txtEdiName.Text;
        objAdminRole.Update();
        lvAdminRole.EditIndex = -1;
        PopulateAdminRole();
    }

    protected void btnAdd_Click(object sender, EventArgs e)
    {

        AdminRole objAdminRole = new AdminRole();
        objAdminRole.RoleName = txtAddName.Text;
        objAdminRole.Add();
        DongDong.Common.MessageBox.Show(this, "添加成功");
        PopulateAdminRole();
    }
}